/*
 *  IconUtil.java
 * 
 *  Created on Jun 29, 2008, 7:10:08 PM
 */

package pl.edu.agh.ssm.monitor.utils;

import javax.swing.Icon;
import org.jdesktop.application.ResourceMap;
import pl.edu.agh.ssm.monitor.SessionMonitorApp;
import pl.edu.agh.ssm.monitor.data.RTSPAnswer;
import pl.edu.agh.ssm.monitor.data.RTSPPacket;
import pl.edu.agh.ssm.monitor.data.SessionConnection;
import pl.edu.agh.ssm.monitor.data.SessionNode;
import pl.edu.agh.ssm.monitor.data.SessionNodeType;

/**
 *
 * @author aneezka
 */
public class IconUtil {
    
    public IconUtil() {
        map = SessionMonitorApp.getApplication().getView().getResourceMap();
    }
    
    public Icon getNodeTypeIcon(SessionNode node) {
        if (node.getNodeType().equals(SessionNodeType.RECEIVER)) {
            return map.getIcon("receiver.icon");
        } else if (node.getNodeType().equals(SessionNodeType.SENDER)) {
            return map.getIcon("sender.icon");
        } else if (node.getNodeType().equals(SessionNodeType.SENDER_AND_RECEIVER)) {
            return map.getIcon("sender_and_receiver.icon");
        } else if (node.getNodeType().equals(SessionNodeType.SERVER)) {
            return map.getIcon("server.icon");
        } else if (node.getNodeType().equals(SessionNodeType.MULTIPLEXER)) {
            return map.getIcon("multiplexer.icon");
        } else {
            return map.getIcon("unknown.icon");
        }
    }
    
    public Icon getConnectionIcon(SessionConnection connection) {
        return map.getIcon("connection.icon");
    }
    
    public Icon getRTSPIcon(RTSPPacket packet) {
        switch (packet.getType()) {
            case ANNOUNCE : return map.getIcon("announce.icon");
            case PLAY : return map.getIcon("play.icon");    
            case DESCRIBE : return map.getIcon("describe.icon");
            case GET_PARAMETER : return map.getIcon("getParameter.icon");
            case OPTIONS : return map.getIcon("options.icon");
            case PAUSE  : return map.getIcon("pause.icon");
            case RECORD : return map.getIcon("record.icon");
            case REDIRECT : return map.getIcon("redirect.icon");
            case SETUP : return map.getIcon("setup.icon");
            case SET_PARAMETER : return map.getIcon("setParameter.icon");
            case TEARDOWN : return map.getIcon("teardown.icon");
            default : return null;
        }
    }
    
    public Icon getRTSPAnswerIcon(RTSPAnswer packet) {
        if (packet.getAnswerCode() >= 100 && packet.getAnswerCode() < 200) {
            return map.getIcon("info.icon");
        } else if (packet.getAnswerCode() >= 200 & packet.getAnswerCode() < 300) {
            return map.getIcon("ok.icon");
        } else if (packet.getAnswerCode() >= 300 && packet.getAnswerCode() < 400) {
            return map.getIcon("redirect.icon");
        } else {
            return map.getIcon("error.icon");
        }
    }
    
    private ResourceMap map;

}
